package com.atguigu.gmall.all.controller;

import com.atguigu.gmall.cart.client.CartFeignClient;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.product.client.ProductFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

/**
 * @author ：Shine
 * @description：
 * @date ：2021/3/2 15:09
 */
@Controller
public class CartController {
    @Autowired
    private CartFeignClient cartFeignClient;

    @Autowired
    private ProductFeignClient productFeignClient;


    @RequestMapping("cart.html")
    public String index(HttpServletRequest request) {
        return "cart/index";
    }

    @RequestMapping("addCart.html")
    public String addToCart(HttpServletRequest request) {
        String skuId = request.getParameter("skuId");
        String skuNum = request.getParameter("skuNum");

        cartFeignClient.addToCart(Long.parseLong(skuId), Integer.parseInt(skuNum));
        SkuInfo skuInfo = productFeignClient.getSkuInfo(Long.parseLong(skuId));

        request.setAttribute("skuInfo", skuInfo);
        request.setAttribute("skuNum", skuNum);
        return "cart/addCart";
    }


}
